<?php
#header('Content-type: text/html; charset=utf-8');
$file = fopen("translations.txt","r");
if (!$file) {
    echo "<p>Unable to open file translations.txt\n";
    exit;
}

$translation = array();

while (!feof ($file)) {
	$line = fgets ($file, 1024);
        $tok1 = strtok($line, " ");
	if ($tok1 !== false) {
	    $tok2 = strtok(" ");
	    if ($tok2 !== false) {
		$translation[$tok1] = $tok2;
	    }
#		echo "tokens 1 and 2 are $tok1 $tok2";
        }
}

$input = $_GET["msg"];
$output = "";

$currInp = strtok($input, " ");
while ($currInp !== false) {
	if (array_key_exists($currInp, $translation)) {
	#	echo "Translation for $currInp is $translation[$currInp]";
		$output .= $translation[$currInp];
	}
	$currInp = strtok(" ");
}
echo $output;
?>
